package com.e.dianshang.service.impl;

import com.e.dianshang.mapper.AddressMapper;
import com.e.dianshang.pojo.Address;
import com.e.dianshang.service.AddressService;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service("addressService")
public class AddressServiceImpl implements AddressService {

    @Resource
    AddressMapper addressMapper;

    @Override
    public List<Address> selectAddress(String openid) {
        Address address=new Address();
        address.setOpenid(openid);
        return addressMapper.select(address);
    }

    @Override
    public Integer insertAddress(Address address) {
        return addressMapper.insert(address);
    }

    @Override
    public Integer updateAddress(Address address) {
        String openid = address.getOpenid();
        Example example=new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("openid",openid);
        return addressMapper.updateByExampleSelective(address,example);
    }

    @Override
    public Integer deleteAddress(String openid) {
        Example example =new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("openid",openid);
        return addressMapper.deleteByExample(example);
    }

    @Override
    public Integer updateAddressState(Address address) {
        String openid = address.getOpenid();
        Example example=new Example(Address.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("openid",openid);
        return addressMapper.updateByExampleSelective(address,example);
    }
}